3  * Copyright 2018 gRPC authors.
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *     http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_LOAD_BALANCER_API_H
 
  20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_LOAD_BALANCER_API_H
 
  22 #include <grpc/support/port_platform.h>
 
  24 #include <grpc/slice_buffer.h>
 
  26 #include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h"
 
  27 #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h"
 
  28 #include "src/core/lib/iomgr/exec_ctx.h"
 
  30 #define XDS_SERVICE_NAME_MAX_LENGTH 128
 
  32 typedef grpc_lb_v1_Server_ip_address_t xds_grpclb_ip_address;
 
  33 typedef grpc_lb_v1_LoadBalanceRequest xds_grpclb_request;
 
  34 typedef grpc_lb_v1_InitialLoadBalanceResponse xds_grpclb_initial_response;
 
  35 typedef grpc_lb_v1_Server xds_grpclb_server;
 
  36 typedef google_protobuf_Duration xds_grpclb_duration;
 
  37 typedef google_protobuf_Timestamp xds_grpclb_timestamp;
 
  40   xds_grpclb_server** servers;
 
  42 } xds_grpclb_serverlist;
 
  44 /** Create a request for a gRPC LB service under \a lb_service_name */
 
  45 xds_grpclb_request* xds_grpclb_request_create(const char* lb_service_name);
 
  46 xds_grpclb_request* xds_grpclb_load_report_request_create_locked(
 
  47     grpc_core::XdsLbClientStats* client_stats);
 
  49 /** Protocol Buffers v3-encode \a request */
 
  50 grpc_slice xds_grpclb_request_encode(const xds_grpclb_request* request);
 
  52 /** Destroy \a request */
 
  53 void xds_grpclb_request_destroy(xds_grpclb_request* request);
 
  55 /** Parse (ie, decode) the bytes in \a encoded_xds_grpclb_response as a \a
 
  56  * xds_grpclb_initial_response */
 
  57 xds_grpclb_initial_response* xds_grpclb_initial_response_parse(
 
  58     const grpc_slice& encoded_xds_grpclb_response);
 
  60 /** Parse the list of servers from an encoded \a xds_grpclb_response */
 
  61 xds_grpclb_serverlist* xds_grpclb_response_parse_serverlist(
 
  62     const grpc_slice& encoded_xds_grpclb_response);
 
  64 /** Return a copy of \a sl. The caller is responsible for calling \a
 
  65  * xds_grpclb_destroy_serverlist on the returned copy. */
 
  66 xds_grpclb_serverlist* xds_grpclb_serverlist_copy(
 
  67     const xds_grpclb_serverlist* sl);
 
  69 bool xds_grpclb_serverlist_equals(const xds_grpclb_serverlist* lhs,
 
  70                                   const xds_grpclb_serverlist* rhs);
 
  72 bool xds_grpclb_server_equals(const xds_grpclb_server* lhs,
 
  73                               const xds_grpclb_server* rhs);
 
  75 /** Destroy \a serverlist */
 
  76 void xds_grpclb_destroy_serverlist(xds_grpclb_serverlist* serverlist);
 
  78 /** Compare \a lhs against \a rhs and return 0 if \a lhs and \a rhs are equal,
 
  79  * < 0 if \a lhs represents a duration shorter than \a rhs and > 0 otherwise */
 
  80 int xds_grpclb_duration_compare(const xds_grpclb_duration* lhs,
 
  81                                 const xds_grpclb_duration* rhs);
 
  83 grpc_millis xds_grpclb_duration_to_millis(xds_grpclb_duration* duration_pb);
 
  85 /** Destroy \a initial_response */
 
  86 void xds_grpclb_initial_response_destroy(xds_grpclb_initial_response* response);
 
  88 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_LOAD_BALANCER_API_H \